12. Implementing Google VR SDK for Unity

Implementing the GVR SDK

Important! The VR camera rig you built during the previous lesson pages, Building Our First VR Camera and Implementing Head Rotation, should be deleted (or disabled) because that camera rig was created for illustration purpose only.

Enabling VR Support and Adding Cardboard SDK

Assuming the Google VR SDK for Unity asset has been imported into your project, you can enable VR with just a few clicks!

Note: The course assets for this lesson have GoogleVR Unity SDK included so there should be no need to download and import it into your Unity project.

To enable VR, simply go to the Unity menu Edit > Project Settings > Player to open the Player Settings in the Inspector:

Next, under the XR Settings section for the platform you are targeting, i.e. iOS or Android:

  1. Check the Virtual Reality Supported checkbox.
  • Click the plus symbol and add Cardboard.

Note: If there are other SDKs already added, you can delete them using the minus symbol.

As long as you have a camera in your scene, your project now supports VR!

Drag & Drop for Added Functionality

One of the neat things about Google VR SDK for Unity is that it has a built-in tool that lets us simulate head rotation and tilt directly in the Unity Game view.

To enable this, simply locate the GvrEditorEmulator prefab located in the Assets > GoogleVR > Prefabs folder, drag it into your scene and position it where you would like the camera located. Then make your camera a child of the GvrEditorEmulator in your scene hierachy and ensure the camera's transform is set to default values, i.e. Position and Rotation is 0, 0, 0 and Scale is 1, 1, 1:

Note: If you plan to move your camera during gameplay via code, make sure the camera is tagged MainCamera in the Inspector, as shown in the image above.

Now, once you enter Game mode, you can use the following controls:

  • To simulate head rotation (rotate around Y axis): Alt + mouse movement.
  • To simulate head tilt (rotate around Z axis): Ctrl + mouse movement.

For quick testing of Unity VR projects, this is super helpful!

Important! In general, the camera should always be nested under a parent gameobject, for example, the GvrEditorEmulator, and have a local position and rotation of 0, 0, 0. To reposition the camera, the parent gameobject should be repositioned and the camera itself should keep its local position and rotation of 0, 0, 0.

GoogleVR Related Changes affecting Course Assets and Starter Project

Since the videos in this course was recorded, there has been multiple updates to Google VR SDK for Unity. The main changes affecting this course are:

  • The GvrViewerMain prefab you see in the Hierarchy during the videos no longer exist in Google VR SDK for Unity and is now represented by the GvrEditorEmulator prefab.
  • The Main Camera you see in the Hierarchy during the videos will typically be nested as a child of the GvrEditorEmulator prefab.

Project Preview: Implementing the Google VR sdk